package JUC.cas;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author mubei
 * @date 2021/11/23
 * @description
 */
public class CASDemo {



    /*
    * CAS
    * Compare   and  set  比较并交换
    * */
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(2021);

        /*
        *  bool compareAndSet(int expectedValue, int newValue) {
        * expectedValue  期望
        * newValue   新的值
        * 如果是期望的值  就会更新
        * cas  是CPU的原语
        * */
        atomicInteger.compareAndSet(2021,2020);
        System.out.println(atomicInteger.get());

        atomicInteger.getAndIncrement();
    }
}
